<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<h:body>

	<ui:composition template="/template/template.xhtml">

		<ui:define name="content">
			<h:form id="courseForm">
				
				<p:panel header="Điều Kiện Tìm Kiếm" columns="1" cellpadding="0"
					style="width:100%">
					<h:panelGrid header="Tìm Kiếm Môn Học" columns="5" cellpadding="1"
						style="width:70%">
						<h:outputLabel value="Khoa (*)" for="depId" />
						<p:selectOneMenu style="width:300px"
							value="#{mbCourse.filter.depId}" required="true" id="depId">
							<f:selectItem itemLabel="Chọn ..." itemValue="" />
							<f:selectItems value="#{mbCourse.depMap}" />
							<p:ajax update="courseId"
								listener="#{mbCourse.handleDepartmentSelected}" />

						</p:selectOneMenu>
						<h:outputLabel value="Môn Học " for="courseId" />
						<p:selectOneMenu style="width:300px"
							value="#{mbCourse.filter.courseId}" required="false"
							id="courseId">
							<f:selectItem itemLabel="Chọn ..." itemValue="" />
							<f:selectItems value="#{mbCourse.courseMap}" />
						</p:selectOneMenu>
						<p:commandButton value="Search"
							actionListener="#{mbCourse.search}"
							update=":courseForm:courseTablePanel"></p:commandButton>
					</h:panelGrid>
				</p:panel>
				<p:panel id="courseTablePanel" style="width:100%">
					<p:dataTable id="courseTable" var="item" paginator="true" rows="5"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink}
											{PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						value="#{mbCourse.list}" rowKey="#{item.id}"
						selection="#{mbCourse.selected}" selectionMode="single">

						<p:ajax event="rowSelect" listener="#{mbCourse.onRowSelect}"
							update=":courseForm:tabPanel">
						</p:ajax>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Mã Môn Học" />
							</f:facet>
							<h:outputText value="#{item.courseId}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Tên Môn Học" />
							</f:facet>
							<h:outputText value="#{item.name}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Mã Khoa" />
							</f:facet>
							<h:outputText value="#{item.depId}" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Mã Chuyên Ngành" />
							</f:facet>
							<h:outputText value="#{item.majorId}" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Thuộc Học Kỳ" />
							</f:facet>
							<h:outputText value="#{item.semester}" />
						</p:column>


						<p:column>
							<f:facet name="header">
								<h:outputText value="Môn Bắt Buộc" />
							</f:facet>
							<p:selectBooleanCheckbox value="#{item.isrequired}"
								disabled="false" immediate="true" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Số Chỉ Lý Thuyết" />
							</f:facet>
							<h:outputText value="#{item.theoryUnit}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Số Chỉ Thục Hành" />
							</f:facet>
							<h:outputText value="#{item.practiseUnit}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Kiểm Tra Giữa Kỳ" />
							</f:facet>
							<p:selectBooleanCheckbox value="#{item.isMidTest}"
								disabled="false" immediate="true" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Đồ Án Môn Học" />
							</f:facet>
							<p:selectBooleanCheckbox value="#{item.isEssays}"
								disabled="false" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Kiểm Tra Cuối Kỳ" />
							</f:facet>
							<p:selectBooleanCheckbox value="#{item.isFinalTest}"
								disabled="false" />
						</p:column>
					</p:dataTable>
				</p:panel>
				<p:panel id="tabPanel" style="width:100%" autoUpdate="true">
					<p:tabView id="courseFactorTab">
						<p:tab title="Hệ Số Điểm Môn Học" id="courseFactorTab">
							<p:dataTable id="scoreFactorTable" var="item" paginator="true"
								paginatorTemplate="{CurrentPageReport}  {FirstPageLink}
											{PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
								rows="5" value="#{mbCourse.courseScoreFactors}"
								rowKey="#{item.id}"
								selection="#{mbCourse.courseScoreFactorSelected}"
								selectionMode="single">

								<p:ajax event="rowSelect"
									listener="#{mbCourse.onFactorRowSelect}"
									update=":courseForm:tabPanel, :editCourseScoreFactorDlg">
								</p:ajax>

								<p:column>
									<f:facet name="header">
										<h:outputText value="Mã Khoa" />
									</f:facet>
									<h:outputText value="#{item.depId}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="Mã Môn Học" />
									</f:facet>
									<h:outputText value="#{item.courseId}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<h:outputText value="Hệ Số Điểm Thi Giữa Kỳ" />
									</f:facet>
									<h:outputText value="#{item.midTestFactor}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<h:outputText value="Hệ Số Điểm Đố Án" />
									</f:facet>
									<h:outputText value="#{item.essaysFactor}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<h:outputText value="Hệ Số Điểm Thi Cuối Kỳ" />
									</f:facet>
									<h:outputText value="#{item.finalTestFactor}" />
								</p:column>
							</p:dataTable>

							<h:panelGrid id="scoreFactorCommandPanel" columns="3">
								<p:commandButton id="addCourseScoreFactor" value="Thêm"
									disabled="#{mbCourse.hasFactor == true}"
									update=":editCourseScoreFactorDlg"
									action="#{mbCourse.prepareAddCourseScoreFactor}"
									oncomplete="editCourseScoreFactorDlgWidget.show()"></p:commandButton>
								<p:commandButton id="editCourseScoreFactor" value="Sửa"
									action="#{mbCourse.prepareEditCourseScoreFactor}"
									update=":editCourseScoreFactorDlg"
									disabled="#{mbCourse.courseScoreFactorSelected == null}"
									oncomplete="editCourseScoreFactorDlgWidget.show()"></p:commandButton>
								<p:commandButton id="deleteCourseScoreFactor" value="Xóa"
									action="#{mbCourse.doDeleteCourseScoreFactor}"
									update="scoreFactorTable,scoreFactorCommandPanel"
									disabled="#{mbCourse.courseScoreFactorSelected == null}">
								</p:commandButton>
							</h:panelGrid>
						</p:tab>
					</p:tabView>
				</p:panel>
			</h:form>
			<script type="text/javascript">
				function handleCourseScoreFactorRequest(xhr, status, args) {
					if (args.validationFailed || !args.validate) {
						jQuery('#editCourseScoreFactorDlgWidget').effect(
								"shake", {times : 3}, 100);
					} else {
						editCourseScoreFactorDlgWidget.hide();
					}
				}
			</script>

			<p:dialog id="editCourseScoreFactorDlg"
				header="#{mbCourse.courseScoreFactorSelected != null ? 'Sửa Thông Tin Hệ Số Điểm' : 'Thêm Hệ Số Điểm Môn Học'}"
				minWidth="500" widgetVar="editCourseScoreFactorDlgWidget"
				resizable="false">
				<p:ajax event="close" update=":courseForm:tabPanel"
					listener="#{mbCourse.handleCourseScoreFactorWindowClose}" />
					
				<h:form id="editCourseScoreFactorForm">
					<p:messages id="message" autoUpdate="true"></p:messages>
					<h:panelGrid columns="2" style="margin-bottom:10px">
						<h:outputLabel for="depId" value="Khoa(*) " />
						<p:inputText size="50" value="#{mbCourse.courseScoreFactor.depId}"
							required="true" id="depId" disabled="true">
						</p:inputText>
						<h:outputLabel for="id" value="Mã Môn Học(*) " />
						<p:inputText id="id"
							value="#{mbCourse.courseScoreFactor.courseId}" required="true"
							label="Mã Môn Học" size="50" disabled="true" />

						<h:outputLabel for="midTestFactor"
							value="Hệ Số Điểm Giữa Kỳ[0->100] " />
						<p:inputText id="midTestFactor"
							value="#{mbCourse.courseScoreFactor.midTestFactor}"
							required="#{mbCourse.selected.isMidTest}"
							label="Hệ Số Điểm Giữa Kỳ" size="50"
							disabled="#{mbCourse.selected.isMidTest == false}" />

						<h:outputLabel for="essaysFactor"
							value="Hệ Số Điểm Đồ Án[0->100] " />
						<p:inputText id="essaysFactor"
							value="#{mbCourse.courseScoreFactor.essaysFactor}"
							required="#{mbCourse.selected.isEssays}" label="Hệ Số Điểm Đồ Án"
							size="50" disabled="#{mbCourse.selected.isEssays == false}" />

						<h:outputLabel for="finalTestFactor"
							value="Hệ Số Điểm Thi Cuối Kỳ[0->100] " />
						<p:inputText id="finalTestFactor"
							value="#{mbCourse.courseScoreFactor.finalTestFactor}"
							required="#{mbCourse.selected.isFinalTest}"
							label="Hệ Số Điểm Thi Cuối Kỳ" size="50"
							disabled="#{mbCourse.selected.isFinalTest == false}" />

						<p:commandButton id="submitButton" value="Lưu"
							action="#{mbCourse.doAddCourseScoreFactor}"
							update=":courseForm:tabPanel, message"
							oncomplete="handleCourseScoreFactorRequest(xhr, status, args)" />
					</h:panelGrid>
				</h:form>
			</p:dialog>
		</ui:define>

	</ui:composition>

</h:body>

</html>